/// <reference path="../typings/index.d.ts" />
/// <reference path="../src/departmentService.ts" />
/// <reference path="../src/tms.ts" />

describe('getDepartmentList',()=>{
    var injector:ng.auto.IInjectorService;
    var service:IDepartmentService;

    beforeEach(()=>{
        injector=angular.injector(['ng','tms']);
        service=injector.get<IDepartmentService>('departmentService');
    });

    //常规无条件获取
    it('get department list normal',(done)=>{
        service.getList(null,0,10).then((res)=>{
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('|0|10');
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //获取部门名称包含 客服 的部门列表
    it('get department list by name \'客服\'',(done)=>{
        service.getList('客服',0,10).then((res)=>{
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('客服|0|10');
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //获取部门详细
    it('get detail',(done)=>{
        service.getDetail('1').then((res)=>{
            expect(res.data.name).toBe("detail");
            expect(res.data.roles.length).toBe(2);
            expect(res.data.types.length).toBe(2);
            expect(res.data.extData).toBe("1");
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //添加部门内容
    it('add department',(done)=>{
        service.add('管理部门',['1','2'],['客服专员','调度专员']).then((res)=>{
            expect(res.data.extData).toBe("管理部门|2|2");
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //编辑部门
    it('edit department',(done)=>{
        service.edit('2','管理部门',['1','2'],['客服专员','调度专员']).then((res)=>{
            expect(res.data.extData).toBe("2|管理部门|2|2");
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //删除部门
    it('delete department',(done)=>{
        service.delete('1').then((res)=>{
            expect(res.data.extData).toBe("1");
            done();
        },(err)=>{
            done.fail(err);
        });
    });

});